package cn.lopr.util.jwt;

import io.jsonwebtoken.JwtBuilder;
import io.jsonwebtoken.Jwts;
import io.jsonwebtoken.SignatureAlgorithm;

import java.util.Date;

/**
 * @author shuangyang7
 * @date 2021/3/27 17:01
 */
public class CreateJwtTest {
    public static void main(String[] args) {
        long now = System.currentTimeMillis();//当前时间
        long exp = now + 1000 * 60;//过期时间为1分钟
        // setIssuedAt用于设置签发时间
        // signWith用于设置签名秘钥
        JwtBuilder builder = Jwts.builder().setId("888")
                .setSubject("大白").setIssuedAt(new Date())
                .setExpiration(new Date(exp))
                .signWith(SignatureAlgorithm.HS256, "cn.lopr");
        System.out.println(builder.compact());
    }
}
